import pandas as pd
from datetime import timedelta, datetime

df = pd.read_csv('./files/history_A_stock_k_data.csv')

list = [
  '2023-06-15',
  '2022-06-17',
  '2021-06-18',
  '2020-06-19',
  '2019-06-20',
  '2018-06-21',
  '2017-06-22',
  '2016-06-23',
  '2015-06-24',
  '2014-06-25',
]
list02 = []

length = len(list)

# demoList = ['2023-06-15','2023-06-16']
# print(df[df['date'].isin(demoList)])
# exit()

def checkDate(strDate):
  num = 1
  while True:
    a = datetime.strptime(strDate, "%Y-%m-%d")
    b = timedelta(days=num)
    dates = a + b
    date = f"{dates.year}-{dates.month:02d}-{dates.day:02d}"
    if(date in df['date'].values):
      return date
    num = num + 1

for i in range(length):
  date = checkDate(list[i])
  list02.append(date)

# print(df[df['date'].isin(list02)])

c = df[df['date'].isin(list02)]
c['get'] = c['preclose'] - c['open']
print(c)
